package com.StarStudio.DAO;

import com.ruoyi.common.core.Entity.GoodsStock;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@SuppressWarnings("all")
public interface GoodsStockDAO {

    List<GoodsStock> findGoodsStockList(GoodsStock goodsStock);
    List<GoodsStock> findGoodsStockListForNormalUser(@Param("goodsStock") GoodsStock goodsStock,@Param("store_id") long store_id);

    @Insert("insert into goods_item values (null,#{goods_id},#{store_id},#{goods_name},#{have_been_sold},#{sold_order_id},#{add_time},#{sold_time},#{del_flag})")
    void addGoodsStock(GoodsStock goodsStock);

    @Delete("delete from goods_item where item_id = #{id}")
    void deleteGoodsStock(int id);

    @Select("select item_id from goods_item where goods_id = #{goods_id} and store_id = #{store_id} and have_been_sold = false")
    List<Long> findGoodsStockIds(@Param("goods_id") long goods_id, @Param("store_id") long store_id);

    @Select("select count(*) from goods_item where del_flag = false")
    long findAllRecordNumber();

    @Select("select * from goods_item where goods_id = #{goods_id} and have_been_sold = #{have_been_sold}")
    List<GoodsStock> findUnsoldItems(@Param("goods_id") long goods_id,@Param("have_been_sold") boolean have_been_sold);

    @Select("select * from goods_item where goods_id = #{goods_id} and have_been_sold = #{have_been_sold}")
    List<GoodsStock> findSoldItems(@Param("goods_id") long goods_id,@Param("have_been_sold") boolean have_been_sold);

    @Update("update goods_item set goods_id = #{goods_id},store_id = #{store_id}, goods_name = #{goods_name},have_been_sold = #{have_been_sold},sold_order_id = #{sold_order_id}," +
            "add_time = #{add_time},sold_time = #{sold_time},del_flag = #{del_flag} where item_id = #{item_id}")
    void updateGoodsStock(GoodsStock goodsStock);

    @Select("select * from goods_item where sold_order_id = #{order_id}")
    List<GoodsStock> findByOrder_id(long order_id);

    @Select("select item_id from goods_item where goods_id = #{goods_id} and have_been_sold = false")
    List<Long> findUnsoldItemIdsByGoodsId(long goods_id);

    @Update("update goods_item set del_flag = true where item_id = #{id}")
    void updateDelFlag(long id);

    List<Long> findSoldItemIdsByGoodsId(long id);

    @Delete("delete from goods_item where item_id = #{id}")
    void realDelete(long id);
}
